package ca.llsutherland.nfl.util;

import java.util.ArrayList;
import java.util.List;


public class ListUtils {

	public static <T> List<T> filter(Iterable<? extends T> allYall, Specification<? super T> spec) {
        List<T> list = new ArrayList<T>();
        for (T yall : allYall) {
            if (spec.isSatisfiedBy(yall)) {
                list.add(yall);
            }
        }
        return list;
    }
    
    public static <T> List<T> reduce(Iterable<? extends T> allYall, Specification<? super T> spec) {
        List<T> list = new ArrayList<T>();
        for (T yall : allYall) {
        	list.add(yall);
            if (spec.isSatisfiedBy(yall)) {
                list.remove(yall);
            }
        }
        return list;
    }
}
